package day14;

public class homework0001 extends Thread {
    private homework001 baozi;

    public homework0001(homework001 baozi) {
        this.baozi = baozi;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (baozi.getLock()) {
                if (baozi.getCount() == 0) {
                    break;
                } else {
                    if (baozi.getSymbol() == false) {
                        System.out.println("厨师做好了一个包子");
                        baozi.setNum(baozi.getNum()+1);
                        if (baozi.getNum()==5){
                            System.out.println("厨师做好了5个包子");
                            baozi.setSymbol(true);
                            baozi.getLock().notify();
                        }
                    } else {
                        try {
                            baozi.getLock().wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
